#!/usr/bin/ruby

#################################
#        MFarp.rb                                                                            
#        description;                                                                          
#            provide arp control functions for MFd.rb                           
#        version           1.2                                                                 
#        last modified     06/22/06                                                            
#       Last change, modified error reporting
#################################
ARP_VERSION=1.2
def modarp(type)
    retary=Array.new
    lines=MFreadlines("/jail/arp/rules")
    lines.each {|line|
    if type == "del"
        tmp=line.split(" ")
        if line.include?(":")
            # standard entry
            if !system("#{$arp} -d #{tmp[0]}")
                retary << "\tFAILED: deleting ARP entry #{line}\n";
            end
        else
            if !system("#{$arp} -d #{tmp[0]} dev #{tmp[1]}")
                retary << "\tFAILED: adding ARP entry #{line}\n";
            end
        end
    else
        if line.include?(":")
            # standard entry
            if !system("#{$arp} -s #{line}")
                retary << "\tFAILED: adding ARP entry #{line}\n";
            end
        else
            if !system("#{$arp} -Ds #{line} pub")
                retary << "\tFAILED: adding ARP entry #{line}\n";
            end
        end
    end
    }
return retary.to_s
end


def arp_stop
    if active?("/jail/arp")
        return modarp("del")
    else
        return "\tNOTICE: ARP CTL not active in config... skipping\n"
    end
end

def arp_start
    if active?("/jail/arp")
        return modarp("add")
    else
        return "\tNOTICE: ARP CTL not active in config... skipping\n"
    end
end

def arp_restart
    arp_stop
    arp_start
end


def arp_ver
   return "\tARP library version: #{ARP_VERSION}\n"
end
